<?php
// 获取反馈信息
// header("content-type:text/html;charset=utf-8");
include_once("conn.php");
if (!session_id()) {
    session_start();
}
if (empty($_GET['action']) || $_GET['action'] != 'search') {
    $sql = "SELECT * FROM tb_feedback 
    LEFT JOIN tb_fixinfo_request ON tb_fixinfo_request.fix_id = tb_feedback.fix_id 
    LEFT JOIN tb_fix_repairer ON tb_fix_repairer.fix_id = tb_feedback.fix_id
    LEFT JOIN tb_repairer ON tb_repairer.r_id = tb_fix_repairer.r_id
    WHERE  tb_feedback.u_id  = '" . $_SESSION['USER']['u_id'] . "' 
    ORDER BY feedback_date DESC"; // 按照日期降序排列
} else {
    $fix_id = $_GET['fid'];
    $sql = "SELECT * FROM tb_feedback 
    LEFT JOIN tb_fixinfo_request ON tb_fixinfo_request.fix_id = tb_feedback.fix_id 
    LEFT JOIN tb_fix_repairer ON tb_fix_repairer.fix_id = tb_feedback.fix_id
    LEFT JOIN tb_repairer ON tb_repairer.r_id = tb_fix_repairer.r_id
    WHERE  tb_feedback.u_id  = '" . $_SESSION['USER']['u_id'] . "' AND tb_feedback.fix_id LIKE '%" . $fix_id . "%'
    ORDER BY feedback_date DESC"; // 按照日期降序排列
}
// 已经提交的反馈信息

$result = mysqli_query($conn_DB, $sql);
if ($result) {
    if (mysqli_num_rows($result) <= 0) {
        echo "
            <div class='feedback-history-content-item'>
                <div class='noneinfo'>
                    暂无反馈信息
                </div>
            </div>
        ";
    } else {
        while ($row = mysqli_fetch_array($result)) {
            echo "
                    <div class='feedback-history-content-item'>
                        <p>报修单号：<span id = 'f_id'>".$row['fix_id']."</span></p>
                        <p>报修人：".$row['fix_name']."</p>
                        <p>提交时间：".$row['fix_sendtime']."</p>
                        <p>维修员工号：".$row['r_id']."</p>
                        <p>维修员姓名：".$row['r_name']."</p>
                        <p>派发任务时间：".$row['r_date']."</p>
                        <p>维修完成时间：".$row['fix_endtime']."</p>
                        <p>故障图：</p>
                        <div class='feedback-history-content-item-img'>
                            <img src='../img/user_upload/".$row['fix_img']."' class='img'>
                        </div>
                        <p>你的反馈：</p>
                        <p>".$row['content']."</p>
                        <div class='del-btn-div'>
                            <button type='button' class='btn btn-outline-danger del-btn' onclick = 'del(".$row[0].")'>删除此反馈信息</button>
                        </div>
                    </div>
            ";
        }
    }
}